<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [6, 3, 9, 22, 16, 4, 7, 66]
      // 求该数组中大于平均值的数的个数，和小于平均值的个数。
      const res = arr.reduce(function (prev, item) {
        return prev + item
      }, 0)
      // console.log(res)
      avg = res / arr.length
      console.log(avg)

      let arr1 = []
      let arr2 = []
      for (let i = 0; i < arr.length; i++) {
        if (avg > arr[i]) {
          arr1.push(arr[i])
        }
        if (avg < arr[i]) {
          arr2.push(arr[i])
        }
      }
      console.log(arr1)
      console.log(arr2)
    </script>
  </body>
</html>
